// ============================================================================
//  TANG EDU BOARD  -  Master Physical Constraints (.cst)
//  FPGA   : Sipeed Tang Nano 9K  (Gowin GW1NR-9, GW1NR-LV9QN88PC6/I5)
//  Source : Beti Elektronik
//
//  This is the FULL board reference. In a real Gowin project, keep only the
//  constraints for the ports your top module actually uses -- otherwise
//  Place & Route reports a "net not found" style error.
//
//  IMPORTANT (SSPI): led[3], led[4], led[5] are on pins 56/55/54, which are the
//  GW1NR-9 SSPI dual-purpose pins. Enable
//      Project > Configuration > Dual-Purpose Pin > "Use SSPI as regular IO"
//  or P&R fails with PR2017 / PR2028.
// ============================================================================

// ---------- Clock : 27 MHz on-board oscillator (Tang Nano 9K module) ----------
IO_LOC  "clk" 52;
IO_PORT "clk" IO_TYPE=LVCMOS33;

// ---------- LEDs  (ACTIVE-LOW : drive '0' to light) --------------------------
IO_LOC  "led[0]" 69;
IO_LOC  "led[1]" 68;
IO_LOC  "led[2]" 57;
IO_LOC  "led[3]" 56;   // SSPI dual-purpose pin (see note above)
IO_LOC  "led[4]" 55;   // SSPI dual-purpose pin (see note above)
IO_LOC  "led[5]" 54;   // SSPI dual-purpose pin (see note above)
IO_LOC  "led[6]" 53;
IO_LOC  "led[7]" 51;
IO_PORT "led[0]" IO_TYPE=LVCMOS33 DRIVE=8;
IO_PORT "led[1]" IO_TYPE=LVCMOS33 DRIVE=8;
IO_PORT "led[2]" IO_TYPE=LVCMOS33 DRIVE=8;
IO_PORT "led[3]" IO_TYPE=LVCMOS33 DRIVE=8;
IO_PORT "led[4]" IO_TYPE=LVCMOS33 DRIVE=8;
IO_PORT "led[5]" IO_TYPE=LVCMOS33 DRIVE=8;
IO_PORT "led[6]" IO_TYPE=LVCMOS33 DRIVE=8;
IO_PORT "led[7]" IO_TYPE=LVCMOS33 DRIVE=8;

// ---------- Slide switches (external pull-up; one pos = 0, other = 1) --------
IO_LOC  "sw[0]" 28;
IO_LOC  "sw[1]" 27;
IO_LOC  "sw[2]" 26;
IO_LOC  "sw[3]" 25;
IO_LOC  "sw[4]" 39;
IO_LOC  "sw[5]" 36;
IO_LOC  "sw[6]" 37;
IO_LOC  "sw[7]" 38;
IO_PORT "sw[0]" IO_TYPE=LVCMOS33 PULL_MODE=NONE;
IO_PORT "sw[1]" IO_TYPE=LVCMOS33 PULL_MODE=NONE;
IO_PORT "sw[2]" IO_TYPE=LVCMOS33 PULL_MODE=NONE;
IO_PORT "sw[3]" IO_TYPE=LVCMOS33 PULL_MODE=NONE;
IO_PORT "sw[4]" IO_TYPE=LVCMOS33 PULL_MODE=NONE;
IO_PORT "sw[5]" IO_TYPE=LVCMOS33 PULL_MODE=NONE;
IO_PORT "sw[6]" IO_TYPE=LVCMOS33 PULL_MODE=NONE;
IO_PORT "sw[7]" IO_TYPE=LVCMOS33 PULL_MODE=NONE;

// ---------- Push buttons (ACTIVE-LOW; RC hardware debounced) -----------------
IO_LOC  "btn[0]" 70;
IO_LOC  "btn[1]" 71;
IO_LOC  "btn[2]" 72;
IO_LOC  "btn[3]" 73;
IO_PORT "btn[0]" IO_TYPE=LVCMOS33 PULL_MODE=NONE;
IO_PORT "btn[1]" IO_TYPE=LVCMOS33 PULL_MODE=NONE;
IO_PORT "btn[2]" IO_TYPE=LVCMOS33 PULL_MODE=NONE;
IO_PORT "btn[3]" IO_TYPE=LVCMOS33 PULL_MODE=NONE;

// ---------- 7-segment display SR420281N  (COMMON CATHODE) -------------------
//  Segment ON   = drive HIGH (through 390R)
//  Digit ENABLE = drive that digit's common LOW
IO_LOC  "seg[0]" 29;   // a
IO_LOC  "seg[1]" 30;   // b
IO_LOC  "seg[2]" 33;   // c
IO_LOC  "seg[3]" 34;   // d
IO_LOC  "seg[4]" 40;   // e  (hardware-verified; eski schematic: 35)
IO_LOC  "seg[5]" 35;   // f  (hardware-verified; eski schematic: 40)
IO_LOC  "seg[6]" 41;   // g
IO_LOC  "seg[7]" 42;   // dp
IO_PORT "seg[0]" IO_TYPE=LVCMOS33 DRIVE=8;
IO_PORT "seg[1]" IO_TYPE=LVCMOS33 DRIVE=8;
IO_PORT "seg[2]" IO_TYPE=LVCMOS33 DRIVE=8;
IO_PORT "seg[3]" IO_TYPE=LVCMOS33 DRIVE=8;
IO_PORT "seg[4]" IO_TYPE=LVCMOS33 DRIVE=8;
IO_PORT "seg[5]" IO_TYPE=LVCMOS33 DRIVE=8;
IO_PORT "seg[6]" IO_TYPE=LVCMOS33 DRIVE=8;
IO_PORT "seg[7]" IO_TYPE=LVCMOS33 DRIVE=8;

IO_LOC  "dig[0]" 74;   // rightmost digit
IO_LOC  "dig[1]" 75;
IO_LOC  "dig[2]" 76;
IO_LOC  "dig[3]" 77;   // leftmost digit
IO_PORT "dig[0]" IO_TYPE=LVCMOS33 DRIVE=8;
IO_PORT "dig[1]" IO_TYPE=LVCMOS33 DRIVE=8;
IO_PORT "dig[2]" IO_TYPE=LVCMOS33 DRIVE=8;
IO_PORT "dig[3]" IO_TYPE=LVCMOS33 DRIVE=8;
